package commandPattern;

import composite.ObjectGroup;
import composite.ObjectItem;

public class RemoveObject implements Command  {
	ObjectGroup rootGroup;
	public void setRootGroup(ObjectGroup rootGroup) {this.rootGroup = rootGroup;}
	ObjectItem oldObject;
	public void setOldObject(ObjectItem oldObject) {this.oldObject = oldObject;}
	
	public void execute() {
		rootGroup.removeObjectItem(oldObject);
	}

	public void redo() {
		rootGroup.removeObjectItem(oldObject);
	}

	public void undo() {
		oldObject.setSelected(false);
		rootGroup.addObjectItem(oldObject);
	}
	
	/** Return a clone of command in state before execution */
	public RemoveObject clone(){
		RemoveObject commandClone = new RemoveObject();
		commandClone.setRootGroup(rootGroup);
		commandClone.setOldObject(oldObject);
		return commandClone;
	}
}